package cn.yuemouren.leetcode;

/**
 * @Author: Timi
 * @Description: 209. 长度最小的子数组 滑动窗口 双指针
 * @Date: 2020/7/29 8:12
 */
public class Test_209 {

    public int minSubArrayLen(int s, int[] nums) {

        int left = 0,right = 0,sum = 0;
        int res = 0;
        while(right < nums.length){
            sum += nums[right++];
            while(sum >= s){
                res = res == 0  ? right - left : Math.min(res,right - left);
                sum -= nums[left++];
            }
        }
        return res;
    }
}
